package com.vitabuybuy.tv.ui.tencent.liveroom.repository

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.LiveDteilaDto
import com.vitabuybuy.tv.ui.tencent.liveroom.bean.GiftListBean
import com.vitabuybuy.tv.ui.tencent.liveroom.bean.LiveGoodsBean
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/3
 * 时间：17:04
 * 包名：com.vitabuybuy.tv.network
 */
object LiveRepository {

    fun joinLive(liveId: Int?): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_join_live_room)
            .add("liveId", liveId)
            .toResponse()
    }

    fun exitLive(liveId: Int?): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_exit_live_room)
            .add("liveId", liveId)
            .toResponse()
    }

    fun livePraise(liveId: Int?): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_live_praise)
            .add("liveId", liveId)
            .toResponse()
    }

    fun getGiftList(liveId: Int?): IAwait<MutableList<GiftListBean>> {
        return RxHttp.postJson(NetUrl.api_live_gift_list)
            .add("pageable", mapOf(Pair("page", 1), Pair("size", 100)))
            .add("liveId", liveId)
            .toResponse()
    }

    fun getGoodsList(liveId: Int?): IAwait<MutableList<LiveGoodsBean>> {
        return RxHttp.postJson(NetUrl.api_live_product)
            .add("id", liveId)
            .toResponse()
    }

    fun openSell(liveId: Int?, productId: Int?): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_live_open_sell)
            .add("liveId", liveId)
            .add("productId", productId)
            .toResponse()
    }

    fun reportAnchor(liveId: Int?, reportString: String?): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_live_report_author)
            .add("report", mapOf(Pair("report", mapOf(Pair("live", mapOf(Pair("id", liveId)))))))
            .add("content", reportString)
            .toResponse()
    }

    fun getViewQuantity(liveId: Int?): IAwait<Int> {
        return RxHttp.postJson(NetUrl.api_live_view_quantity)
            .add("id", liveId)
            .toResponse()
    }

    fun sendGift(liveId: Int?, giftId: Int?, quantity: Int?): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_live_send_gift)
            .add("liveId", liveId)
            .add("giftId", giftId)
            .add("quantity", quantity)
            .toResponse()
    }

    fun getLiveDetail(liveId: Int?): IAwait<LiveDteilaDto> {
        return RxHttp.postJson(NetUrl.api_get_live_details)
            .add("id", liveId)
            .toResponse()
    }


    fun collectOrcancelStore(id: Int?, isFav: Boolean): IAwait<String> {
        return if (isFav) {
            RxHttp.postJson(NetUrl.api_delete_follow_store)
                .add("store", mapOf(Pair("id", id)))
                .toResponse()
        } else {
            RxHttp.postJson(NetUrl.api_follow_store)
                .add("attention", mapOf(Pair("store", mapOf(Pair("id", id)))))
                .toResponse()
        }
    }
}